//
//  ZXDictionaryExtension.swift
//  ExtensionTest
//
//  Created by ZX on 2025/2/12.
//

import Foundation


public extension Dictionary {
    var toJsonStr : String? {
        do {
            // 将字典转换为 JSON 数据
            let jsonData = try JSONSerialization.data(withJSONObject: self, options:.prettyPrinted)
            // 将 JSON 数据转换为字符串
            if let jsonString = String(data: jsonData, encoding:.utf8) {
                return jsonString
            }
        } catch {
            print("JSON 转换出错: \(error)")
        }
        return nil
    }
}
